package com.goblin.model.uaa.po;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.goblin.model.base.BaseEntity;
import lombok.Data;

@Data
@Table(name = "t_test_uaa_role")
@Entity
public class Role extends BaseEntity {

	private static final long serialVersionUID = 3616831768148445574L;

	@Column(name = "label", nullable = false, columnDefinition = " varchar(255) COMMENT '角色名称'")
	private String label;

	@Column(name = "detail", nullable = false, columnDefinition = " varchar(255) COMMENT '角色描述'")
	private String detail;

	@Column(name = "memo", columnDefinition = " varchar(255) COMMENT '角色备注'")
	private String memo;

	//all: 所有情况下均进行关联操作，即save-update和delete。
	//FetchType.EAGER：急加载，加载一个实体时，定义急加载的属性会立即从数据库中加载
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "t_test_role_priv", joinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "priv_id", referencedColumnName = "id"), foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
	private List<Priv> privs;

	//all: 所有情况下均进行关联操作，即save-update和delete。
	//FetchType.EAGER：急加载，加载一个实体时，定义急加载的属性会立即从数据库中加载
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "t_test_role_menu", joinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "menu_id", referencedColumnName = "id"), foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
	private List<Menu> menus;
}
